Skip to content

refactor(metaevent): Split MetaEventTranslator::translateGameMessage() into smaller functions#2758

Open
xezon wants to merge 2 commits into
TheSuperHackers:mainfrom
xezon:xezon/refactor-metaevent
Open

refactor(metaevent): Split MetaEventTranslator::translateGameMessage() into smaller functions#2758
xezon wants to merge 2 commits into
TheSuperHackers:mainfrom
xezon:xezon/refactor-metaevent

Conversation

@xezon
Copy link
Copy Markdown

@xezon xezon commented May 30, 2026

This change splits MetaEventTranslator::translateGameMessage() into smaller functions for better maintainability.

Logically it should function the same.

TODO

  • Replicate in Generals

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing labels May 30, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 30, 2026

Greptile Summary

This PR refactors MetaEventTranslator::translateGameMessage() by extracting six helper methods — onMouseEvent, onKeyEvent, onKeyModStateRemoved, onKeyPressed, getActionKeyType, and getKeyModState — improving readability without changing observable behavior.

  • getActionKeyType and getKeyModState are pure static helpers that map raw system keys/states to MappableKeyType/MappableKeyModState, cleanly replacing the inline switch and bitmask logic.
  • onKeyModStateRemoved faithfully extracts the modifier-key-release path, and onKeyPressed extracts the normal key-down/up dispatch path including the setKeyModState/clearKeyModState bookkeeping.
  • onMouseEvent is a straight lift of the mouse-button handling switch into its own method.

Confidence Score: 5/5

Pure structural refactoring — all logic paths are faithfully preserved from the original monolithic function.

Every branch in the original translateGameMessage maps 1-to-1 to its extracted helper. The modifier-release path (onKeyModStateRemoved), normal key-dispatch path (onKeyPressed), and mouse-button path (onMouseEvent) all carry the same conditions and state mutations as before. The two concerns raised in previous threads (public visibility, message-type vs flag-check for key direction) are pre-existing discussions and do not introduce new behavioral regressions.

No files require special attention beyond the open visibility thread on the header.

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h Adds six new helper method declarations to MetaEventTranslator in the public section; visibility concern already tracked in prior review thread.
GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp translateGameMessage split into six smaller methods; logic is preserved faithfully across all branches including the modifier-key-release path and key-down bookkeeping.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["translateGameMessage(msg)"] --> B{msg type?}
    B -->|KEY_DOWN or KEY_UP| C["onKeyEvent(msg, disp)"]
    B -->|RAW_MOUSE_BEGIN..END| D["onMouseEvent(msg)"]
    B -->|other| E["return KEEP_MESSAGE"]

    C --> F["getActionKeyType(systemKey) → keyType"]
    C --> G["getKeyModState(systemKeyState) → keyModState"]
    C --> H{keyType == MK_NONE AND KEY_UP?}
    H -->|yes — modifier released| I["onKeyModStateRemoved(disp, keyModState)"]
    H -->|no — regular key event| J["onKeyPressed(disp, systemKeyState, keyType, keyModState)"]

    I --> I1["Iterate m_keyDownInfos\nfire UP meta-events\nclearKeyModState"]

    J --> J1["Iterate TheMetaMap\ndispatch meta-event if match"]
    J --> J2{KEY_STATE_DOWN?}
    J2 -->|yes| J3["setKeyModState for keyType"]
    J2 -->|no| J4["clearKeyModState for keyType"]

    D --> D1["Resolve mouse button index\n(LEFT/MIDDLE/RIGHT via FALLTHROUGH)"]
    D1 --> D2{event kind}
    D2 -->|DOWN| D3["record m_mouseDownPosition\nclear double-click flag"]
    D2 -->|DOUBLE CLICK| D4["set double-click flag"]
    D2 -->|UP| D5["insert CLICK or DOUBLE_CLICK message\nappend region + modifiers"]
Loading

Reviews (2): Last reviewed commit: "Make private" | Re-trigger Greptile

Comment thread GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant